package com.laf.manage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.laf.common.utils.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

import com.laf.manage.mapper.mp.TagMapper;
import com.laf.manage.domain.po.Tag;
import com.laf.manage.service.ITagService;

/**
 * 标签Service业务层处理
 *
 * @author zian
 * @date 2024-11-09
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {

    @Autowired
    private TagMapper tagMapper;

    /**
     * 查询标签列表
     *
     * @param tag 标签
     * @return 标签
     */
    @Override
    public List<Tag> selectTagList(Tag tag)
    {
        List<Tag> tagList = tagMapper.selectList(buildQueryWrapper(tag));
        return tagList;
    }


    private LambdaQueryWrapper<Tag> buildQueryWrapper(Tag query) {
        LocalDateTime beginTime = query.getBeginTime();
        LocalDateTime endTime = query.getEndTime();
        LambdaQueryWrapper<Tag> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getTagName()), Tag::getTagName, query.getTagName());
        lqw.between(beginTime != null && endTime!= null, Tag::getCreateTime, beginTime, endTime);
        lqw.orderByDesc(Tag::getCreateTime);
        return lqw;
    }

}
